package com.example.Mapper;

import com.example.Model.QutionAllModel;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.net.PortUnreachableException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//获取题目信息
@Mapper
public interface Topic_Mapper {

    @Select("SELECT  B.Name,B.`describe`,A.Qid,B.Difficulty,\"32%\" as adopt FROM Oj_Topic  as A INNER JOIN Oj_Qution  as B ON A.Qid=B.id")
    public List<QutionAllModel> getTopicAll();

    @Select("SELECT C.`describe`,B.* FROM Oj_Topic as A  INNER JOIN Oj_Code as B INNER JOIN Oj_Qution  as C  ON C.id=B.id AND  A.Cid=B.id  AND A.Qid=#{qid}")
    public HashMap<String,Object> getTopicBody(int qid);

    @Insert("INSERT into Oj_Code(javaCodetempter,pyCodetempter) VALUES(#{Java)},#{Python3})")
    @Options(useGeneratedKeys = true ,keyProperty = "id",keyColumn = "id")
    public int AddCodeTempter(Map<String,String> data);

    @Insert("INSERT into oj_JudgeHead(Java,Python3) VALUES(#{Java},#{Python3})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    public int AddCodeHead(Map<String,String> data);


    @Insert("insert into Oj_Qution(describe,Name,input,result,Difficulty,jid) "+
            "Values(#{data.descr)},#{data.name},#{data.get(\"input\")},"+
            "#{data.get(\"result\")},"+"#{data.get(\"Difficulty\")},"+"#{jid}")
    public int addQution(Map<String,String> data,int jid);


    @Insert("insert into Oj_Topic(Qid,Cid) values(#{qid},#{cid})")
    public int addTopic(int qid,int cid);


}
